//
//  SortDetailTableViewCell.m
//  TasteEnjoy
//
//  Created by XuRui on 16/4/21.
//  Copyright © 2016年 XuRui. All rights reserved.
//

#import "SortDetailTableViewCell.h"

@interface SortDetailTableViewCell ()

@property (nonatomic, retain) BaseImageView *imgPhoto; /**< 图像 */
@property (nonatomic, retain) BaseLabel *labelname; /**< 标题 */
@property (nonatomic, retain) BaseLabel *labelPrice; /**< 钱 */
@property (nonatomic, retain) BaseLabel *labelKuaidi; /**< 快递 */

@property (nonatomic, retain) BaseImageView *imgKuaidi; /**< 快递 */
@end

@implementation SortDetailTableViewCell


- (void)dealloc
{
    [_imgPhoto release];
    [_labelname release];
    [_labelPrice release];
    [_labelKuaidi release];
    [_imgKuaidi release];
    [_model release];
    [super dealloc];
    
}


#pragma mark - ------------ 初始化 ---------------
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubViews];
    }
    return self;
}

#pragma mark - ------------ 创建子视图 ---------------
- (void)createSubViews
{

    self.imgPhoto = [[BaseImageView alloc]init];
    [self.contentView addSubview:_imgPhoto];
    _imgPhoto.contentMode = UIViewContentModeScaleAspectFill;
    _imgPhoto.clipsToBounds = YES;
    
    self.labelname = [[BaseLabel alloc]init];
    [self.contentView addSubview:_labelname];
/** 夜间 */
    _labelname.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor lightGrayColor]);
    
    self.labelPrice = [[BaseLabel alloc]init];
    [self.contentView addSubview:_labelPrice];
    
    self.labelKuaidi = [[BaseLabel alloc]init];
    [self.contentView addSubview:_labelKuaidi];
    
    self.imgKuaidi = [[BaseImageView alloc]init];
    [self.contentView addSubview:_imgKuaidi];

    
//    _imgPhoto.backgroundColor = [UIColor orangeColor];
//    _labelname.backgroundColor = [UIColor grayColor];
//    
//    _labelPrice.backgroundColor = [UIColor grayColor];
//    _labelKuaidi.backgroundColor = [UIColor yellowColor];
//    _imgKuaidi.backgroundColor = [UIColor redColor];
    
    [_imgPhoto release];
    [_labelname release];
    [_labelPrice release];
    [_labelKuaidi release];
    [_imgKuaidi release];
}

#pragma mark - ------------ 赋大小 ---------------
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [_imgPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.mas_equalTo(self.contentView).offset(10);
        
        make.bottom.mas_equalTo(self.contentView).offset(-10);
        
        make.width.mas_equalTo(self.contentView.frame.size.width * 1/2 - 30);
    }];
    
    [_labelname mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.contentView).offset(10);
        make.right.mas_equalTo(self.contentView).offset(-10);
        make.left.mas_equalTo(_imgPhoto.mas_right).offset(10);
        make.bottom.mas_equalTo(_labelPrice.mas_top).offset(0);
        make.height.mas_equalTo(70);
    }];
    
    [_labelPrice mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.contentView).offset(-15);
        make.width.mas_equalTo(70);
        make.bottom.mas_equalTo(_labelKuaidi.mas_top).offset(-5);
        make.height.mas_equalTo(30);
    }];
    
    [_imgKuaidi mas_makeConstraints:^(MASConstraintMaker *make) {
       
        // make.left.mas_equalTo(_imgPhoto.mas_right).offset(10);
         make.top.mas_equalTo(_labelPrice.mas_bottom).offset(5);
         make.bottom.mas_equalTo(_imgPhoto);
         make.right.mas_equalTo(_labelKuaidi.mas_left).offset(0);
        make.width.mas_equalTo(30);
    }];

    
    [_labelKuaidi mas_makeConstraints:^(MASConstraintMaker *make) {
   
        make.right.mas_equalTo(self.contentView).offset(-15);
        make.width.mas_equalTo(40);
        
        make.bottom.mas_equalTo(_imgPhoto);

    }];




}


#pragma mark - ------------ 重写赋值 ---------------
- (void)setModel:(EDetailModel *)model
{

    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [_imgPhoto sd_setImageWithURL:[NSURL URLWithString:model.product_image] placeholderImage:PLACEHOLDER];
   
    _labelname.text = model.name;
    _labelname.font = [UIFont systemFontOfSize:15];
    _labelname.numberOfLines = 0;
    
    NSInteger i = model.price.integerValue / 100;
   
    NSString *str = [NSString stringWithFormat:@"%ld", (long)i];
    _labelPrice.text = [NSString stringWithFormat:@"%@%@/%@", str, @"元", model.entity_name];
    _labelPrice.textColor = [UIColor redColor];
    _labelPrice.textAlignment = NSTextAlignmentRight;
    _labelPrice.font = [UIFont systemFontOfSize:15];

    _imgKuaidi.image = [UIImage imageNamed:@"kk"];
    _labelKuaidi.text = [model.stunt substringToIndex:2];
  
    _labelKuaidi.textAlignment = NSTextAlignmentCenter;
    _labelKuaidi.font = [UIFont systemFontOfSize:15];
    _labelKuaidi.textColor = [UIColor lightGrayColor];
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
